/**
 * <copyright>
 * </copyright>
 *

 */
package org.xtext.example.cr.cR.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.xtext.example.cr.cR.Array;
import org.xtext.example.cr.cR.CRPackage;
import org.xtext.example.cr.cR.Element;
import org.xtext.example.cr.cR.Folder;
import org.xtext.example.cr.cR.For;
import org.xtext.example.cr.cR.SimpleVariable;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>For</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.xtext.example.cr.cR.impl.ForImpl#getFunction <em>Function</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.ForImpl#getLocVar <em>Loc Var</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.ForImpl#getDir <em>Dir</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.ForImpl#getInnerElements <em>Inner Elements</em>}</li>
 *   <li>{@link org.xtext.example.cr.cR.impl.ForImpl#getVar <em>Var</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ForImpl extends MinimalEObjectImpl.Container implements For
{
  /**
   * The default value of the '{@link #getFunction() <em>Function</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFunction()
   * @generated
   * @ordered
   */
  protected static final String FUNCTION_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getFunction() <em>Function</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFunction()
   * @generated
   * @ordered
   */
  protected String function = FUNCTION_EDEFAULT;

  /**
   * The cached value of the '{@link #getLocVar() <em>Loc Var</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getLocVar()
   * @generated
   * @ordered
   */
  protected SimpleVariable locVar;

  /**
   * The cached value of the '{@link #getDir() <em>Dir</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getDir()
   * @generated
   * @ordered
   */
  protected Folder dir;

  /**
   * The cached value of the '{@link #getInnerElements() <em>Inner Elements</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getInnerElements()
   * @generated
   * @ordered
   */
  protected EList<Element> innerElements;

  /**
   * The cached value of the '{@link #getVar() <em>Var</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getVar()
   * @generated
   * @ordered
   */
  protected Array var;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected ForImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return CRPackage.Literals.FOR;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getFunction()
  {
    return function;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setFunction(String newFunction)
  {
    String oldFunction = function;
    function = newFunction;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.FOR__FUNCTION, oldFunction, function));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public SimpleVariable getLocVar()
  {
    if (locVar != null && locVar.eIsProxy())
    {
      InternalEObject oldLocVar = (InternalEObject)locVar;
      locVar = (SimpleVariable)eResolveProxy(oldLocVar);
      if (locVar != oldLocVar)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, CRPackage.FOR__LOC_VAR, oldLocVar, locVar));
      }
    }
    return locVar;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public SimpleVariable basicGetLocVar()
  {
    return locVar;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setLocVar(SimpleVariable newLocVar)
  {
    SimpleVariable oldLocVar = locVar;
    locVar = newLocVar;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.FOR__LOC_VAR, oldLocVar, locVar));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Folder getDir()
  {
    return dir;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetDir(Folder newDir, NotificationChain msgs)
  {
    Folder oldDir = dir;
    dir = newDir;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CRPackage.FOR__DIR, oldDir, newDir);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setDir(Folder newDir)
  {
    if (newDir != dir)
    {
      NotificationChain msgs = null;
      if (dir != null)
        msgs = ((InternalEObject)dir).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - CRPackage.FOR__DIR, null, msgs);
      if (newDir != null)
        msgs = ((InternalEObject)newDir).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - CRPackage.FOR__DIR, null, msgs);
      msgs = basicSetDir(newDir, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.FOR__DIR, newDir, newDir));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Element> getInnerElements()
  {
    if (innerElements == null)
    {
      innerElements = new EObjectContainmentEList<Element>(Element.class, this, CRPackage.FOR__INNER_ELEMENTS);
    }
    return innerElements;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Array getVar()
  {
    if (var != null && var.eIsProxy())
    {
      InternalEObject oldVar = (InternalEObject)var;
      var = (Array)eResolveProxy(oldVar);
      if (var != oldVar)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, CRPackage.FOR__VAR, oldVar, var));
      }
    }
    return var;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Array basicGetVar()
  {
    return var;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setVar(Array newVar)
  {
    Array oldVar = var;
    var = newVar;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRPackage.FOR__VAR, oldVar, var));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case CRPackage.FOR__DIR:
        return basicSetDir(null, msgs);
      case CRPackage.FOR__INNER_ELEMENTS:
        return ((InternalEList<?>)getInnerElements()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case CRPackage.FOR__FUNCTION:
        return getFunction();
      case CRPackage.FOR__LOC_VAR:
        if (resolve) return getLocVar();
        return basicGetLocVar();
      case CRPackage.FOR__DIR:
        return getDir();
      case CRPackage.FOR__INNER_ELEMENTS:
        return getInnerElements();
      case CRPackage.FOR__VAR:
        if (resolve) return getVar();
        return basicGetVar();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case CRPackage.FOR__FUNCTION:
        setFunction((String)newValue);
        return;
      case CRPackage.FOR__LOC_VAR:
        setLocVar((SimpleVariable)newValue);
        return;
      case CRPackage.FOR__DIR:
        setDir((Folder)newValue);
        return;
      case CRPackage.FOR__INNER_ELEMENTS:
        getInnerElements().clear();
        getInnerElements().addAll((Collection<? extends Element>)newValue);
        return;
      case CRPackage.FOR__VAR:
        setVar((Array)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case CRPackage.FOR__FUNCTION:
        setFunction(FUNCTION_EDEFAULT);
        return;
      case CRPackage.FOR__LOC_VAR:
        setLocVar((SimpleVariable)null);
        return;
      case CRPackage.FOR__DIR:
        setDir((Folder)null);
        return;
      case CRPackage.FOR__INNER_ELEMENTS:
        getInnerElements().clear();
        return;
      case CRPackage.FOR__VAR:
        setVar((Array)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case CRPackage.FOR__FUNCTION:
        return FUNCTION_EDEFAULT == null ? function != null : !FUNCTION_EDEFAULT.equals(function);
      case CRPackage.FOR__LOC_VAR:
        return locVar != null;
      case CRPackage.FOR__DIR:
        return dir != null;
      case CRPackage.FOR__INNER_ELEMENTS:
        return innerElements != null && !innerElements.isEmpty();
      case CRPackage.FOR__VAR:
        return var != null;
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (function: ");
    result.append(function);
    result.append(')');
    return result.toString();
  }

} //ForImpl
